package com.itmk.web.sys_suggestion.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itmk.utils.ResultUtils;
import com.itmk.utils.ResultVo;
import com.itmk.web.sys_suggestion.entity.SuggestionParm;
import com.itmk.web.sys_suggestion.entity.SysSuggestion;
import com.itmk.web.sys_suggestion.service.SysSuggestionService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author java实战基地
 * @since 2024-01-24
 */
@RestController
@RequestMapping("/api/sysSuggestion")
public class SysSuggestionController {
    @Autowired
    private SysSuggestionService sysSuggestionService;

    //删除
    @DeleteMapping("/{id}")
    public ResultVo delete(@PathVariable("id") Integer id){
        if(sysSuggestionService.removeById(id)){
            return ResultUtils.success("删除成功!");
        }
        return ResultUtils.error("删除失败!");
    }

    //列表
    @GetMapping("/getList")
    public ResultVo getList(SuggestionParm parm){
        //构造分页对象
        IPage<SysSuggestion> page = new Page<>(parm.getCurrentPage(),parm.getPageSize());
        //构造查询条件
        QueryWrapper<SysSuggestion> query = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(parm.getTitle())){
            query.lambda().like(SysSuggestion::getTitle,parm.getTitle())
                    .or().like(SysSuggestion::getContent,parm.getTitle());
        }
        query.lambda().orderByDesc(SysSuggestion::getCreateTime);
        IPage<SysSuggestion> list = sysSuggestionService.page(page, query);
        return ResultUtils.success("查询成功",list);
    }

}

